package com.ruoyi.stock2.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.stock2.domain.SearchFromEsChoose;
import com.ruoyi.stock2.service.ISearchFromEsChooseService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 精挑细选的Controller
 * 
 * @author ruoyi
 * @date 2021-09-08
 */
@Controller
@RequestMapping("/stock2/choose")
public class SearchFromEsChooseController extends BaseController
{
    private String prefix = "stock2/choose";

    @Autowired
    private ISearchFromEsChooseService searchFromEsChooseService;

    @RequiresPermissions("stock2:choose:view")
    @GetMapping()
    public String choose()
    {
        return prefix + "/choose";
    }

    /**
     * 查询精挑细选的列表
     */
    @RequiresPermissions("stock2:choose:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(SearchFromEsChoose searchFromEsChoose)
    {
        startPage();
        List<SearchFromEsChoose> list = searchFromEsChooseService.selectSearchFromEsChooseList(searchFromEsChoose);
        return getDataTable(list);
    }

    /**
     * 导出精挑细选的列表
     */
    @RequiresPermissions("stock2:choose:export")
    @Log(title = "精挑细选的", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(SearchFromEsChoose searchFromEsChoose)
    {
        List<SearchFromEsChoose> list = searchFromEsChooseService.selectSearchFromEsChooseList(searchFromEsChoose);
        ExcelUtil<SearchFromEsChoose> util = new ExcelUtil<SearchFromEsChoose>(SearchFromEsChoose.class);
        return util.exportExcel(list, "choose");
    }

    /**
     * 新增精挑细选的
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存精挑细选的
     */
    @RequiresPermissions("stock2:choose:add")
    @Log(title = "精挑细选的", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(SearchFromEsChoose searchFromEsChoose)
    {
        return toAjax(searchFromEsChooseService.insertSearchFromEsChoose(searchFromEsChoose));
    }

    /**
     * 修改精挑细选的
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        SearchFromEsChoose searchFromEsChoose = searchFromEsChooseService.selectSearchFromEsChooseById(id);
        mmap.put("searchFromEsChoose", searchFromEsChoose);
        return prefix + "/edit";
    }

    /**
     * 修改保存精挑细选的
     */
    @RequiresPermissions("stock2:choose:edit")
    @Log(title = "精挑细选的", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(SearchFromEsChoose searchFromEsChoose)
    {
        return toAjax(searchFromEsChooseService.updateSearchFromEsChoose(searchFromEsChoose));
    }

    /**
     * 删除精挑细选的
     */
    @RequiresPermissions("stock2:choose:remove")
    @Log(title = "精挑细选的", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(searchFromEsChooseService.deleteSearchFromEsChooseByIds(ids));
    }
}
